#!/usr/bin/bash
#
# Login docker and check mysql/redis/zookeeper/kafka
#

docker_name=${1:-"mysql"}
docker_id=$(sudo docker ps | grep -E "$docker_name" | awk '{print $1}')
[[ -z "$docker_id" ]] && echo "Oops, failed to get docker ID by name $docker_name" >&2 && exit 1

case "$docker_name" in
"mysql")
	echo ">>>"
	echo ">>> mysql -h 127.0.0.1 -P 3306 -u root -p"
	echo ">>>"
	;;
"redis")
	echo ">>>"
	echo ">>> redis-cli -h localhost -p 6379 -a <password>"
	echo ">>>"
	;;
"zookeeper")
	echo ">>>"
	echo ">>> bin/zkCli.sh -server localhost:2181"
	echo ">>>"
	;;
"kafka")
	echo ">>>"
	echo ">>> kafka-topics.sh --bootstrap-server localhost:9092 --list"
	echo ">>> kafka-topics.sh --bootstrap-server localhost:9092 --create --topic foo --partitions 3 --replication-factor 1"
	echo ">>> kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic foo"
	echo ">>> kafka-console-producer.sh --bootstrap-server localhost:9092 --topic foo"
	echo ">>> kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic foo --from-beginning"
	echo ">>> kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic foo"
	echo ">>> kafka-topics.sh --bootstrap-server localhost:9092 --list"
	echo ">>>"
	;;
*)
	;;
esac

sudo docker exec -it "$docker_id" bash
